sum of substrings codeforces solution

visit shbcf.ru